import { ALIVE_IFRAME } from '../../constants/index';

//支付宝支付
export class AliPayment {
  pay(payInfoObj) {
    const { backUrl, srcUrl, payUrl, origin, orderId, tradeId } = payInfoObj;
    return new Promise((resolve, reject) => {
      try {
        const url = `${origin}/v1/goods/ali_pay?payUrl=${payUrl}&orderId=${orderId}&srcUrl=${srcUrl}&backUrl=${backUrl}&app_id=${window.APPID}&isNewOrderPath=1&trade_id=${tradeId}&channel=${ALIVE_IFRAME}`;
        // 抛出中间页url，由业务侧跳转支付宝中间页
        parent.postMessage(
          {
            name: "ali_pay",
            value: url,
          },
          window.location.origin
        );
        resolve();
      } catch (error) {
        reject(error);
      }
    });
  }
}
